@extends('layouts.header')
@section('content')
<article class="page-container">
    <div class="">
        <table class="table table-border table-bordered table-hover table-bg table-responsive" id="datatable">
            <thead>
                <tr class="text-c">
                    <th>本系统工器具类型</th>
                    <th>本系统检测标准</th>
                    <th>本系统检测项目</th>
                    <th>本系统数据=>带电作业数据 &nbsp; &nbsp; &nbsp;<span class="c-red">本系统试验值 x 倍数 = 带电作业试验值</span></th>
                </tr>
            </thead>
            <tbody>
                @foreach ($data['items'] as $tool_name => $item)
                    @php $toolRow = ''; @endphp
                    @foreach ($item as $std_num => $item2)
                        @if($std_num !== 'rows')
                            @foreach($item2 as $k=> $item3)
                                @php $showTool = $toolRow == $tool_name ? 0 : 1; @endphp
                                <tr class="text-c">
                                    @if($showTool)
                                    <td rowspan="{{$item['rows']}}">{{ $tool_name }}</td>
                                    @endif
                                    @if($k == 0)
                                    <td rowspan="{{count($item2)}}">{{ $std_num }}</td>
                                    @endif
                                    <td>{{$item3->item_name}}</td>
                                    <td class="text-l" style="width:50%;">
                                        @foreach($item3->keys as $key)
                                        <form class="ml-10">
                                            {{$key->data_key}}({{$key->data_unit}}) =>
                                            <select name="keyData[{{$key->id}}][key]" class="select2 input-text mt-5" style="width:150px;">
                                                <option value="">--请选择--</option>
                                                @foreach($data['Sditems'] as $proTypeId=>$sdItem)
                                                    @if(isset($data['itemMaps'][$item3->item_name]) && in_array($sdItem['name'],$data['itemMaps'][$item3->item_name]))
                                                    <option value="">{{$sdItem['name']}}</option>
                                                        @foreach($sdItem['upload'] as $keyK=>$keyName)
                                                            @if(isset($data['SditemKeys'][$key->id]) && $data['SditemKeys'][$key->id]->key == $keyK && $data['SditemKeys'][$key->id]->mean == $keyName && $data['SditemKeys'][$key->id]->pro_type_id == $proTypeId)
                                                                <option value="{{$keyK}}-{{$keyName}}-{{$proTypeId}}" selected>&nbsp;&nbsp;--{{$keyName}}</option>
                                                            @else
                                                                <option value="{{$keyK}}-{{$keyName}}-{{$proTypeId}}">&nbsp;&nbsp;--{{$keyName}}</option>
                                                            @endif
                                                        @endforeach
                                                    @endif
                                                @endforeach
                                            </select>
                                            <input type="text" name="keyData[{{$key->id}}][bei]" placeholder="倍数" value="1" class="input-text" style="width:50px;" />
                                            <span class="btn btn-primary radius size-MINI" onclick="mapKey(this)">保存</span>
                                        </form>
                                        @endforeach
                                    </td>
                                </tr>
                                @php $toolRow = $tool_name; @endphp
                            @endforeach
                        @endif
                    @endforeach
                @endforeach
            </tbody>
        </table>
    </div>
</article>

<script type="text/javascript">
    function mapKey(obj) {
        let formData = $(obj).closest('form').serialize();
        console.log(formData);
        ajax('post','',formData);
    }
</script>
@endsection